﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Card.Web.Member
{
    public partial class ConfirmOrder : MemberBase
    {
        #region
        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrderID
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["oid"]))
                {
                    return Request.QueryString["oid"];
                }
                return string.Empty;
            }
        }

      

        #endregion

        #region
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.DoInit();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            this.btnSubmit.Click += new EventHandler(btnSubmit_Click);
            base.OnInit(e);
        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            Entity.Order order = BLL.OrderManager.GetEntity(this.OrderID, this.Passport);
            if (order != null)
            {
                order.Remark = this.txtRemark.Text.Trim();
                if (string.Compare(order.OrderStatusCode, CONST.ORDER_SATTUS.WAIT_PAY, true) == 0)
                {
                    order.OrderStatusCode = CONST.ORDER_SATTUS.WAIT_CONFIRM;
                    if (BLL.OrderManager.Update(order, this.Passport))
                    {
                        Response.Redirect(string.Format("OrderDetail.aspx?oid={0}", this.OrderID));
                    }
                }
            }
        }
        #endregion

        #region
        private void DoInit()
        {
            Entity.Order order = BLL.OrderManager.GetEntity(this.OrderID, this.Passport);
            if (order != null
                && order.UserID == this.Passport.UserID
                && string.Compare(order.OrderStatusCode, CONST.ORDER_SATTUS.WAIT_PAY, true) == 0)
            {
                this.ltlOrderID.Text = order.OrderID;
                this.ltlTotalMoney.Text = order.TotalMoney.ToString();
                this.ltlReceiver.Text = order.Receiver;
                this.ltlPhone.Text = order.Phone;
                this.ltlAddress.Text = order.Address;
                BAF.Entity.LookupValue lookUpSipping = Common.LookUpCache.GetLookupValue(CONST.LOOKUP_TYPE.SIPPING_DATE, order.SippingDateCode);
                if (lookUpSipping != null)
                {
                    this.ltlSippingDate.Text = lookUpSipping.Value;
                }

                BAF.Entity.LookupValue lookUpPayment = Common.LookUpCache.GetLookupValue(CONST.LOOKUP_TYPE.PAYMENT_METHOD, order.PaymentMethodCode);
                if (lookUpPayment != null)
                {
                    this.ltlPayment.Text = lookUpPayment.Value;
                    if (string.Compare(lookUpPayment.LookupCode, "ZZHK") == 0)
                    {
                        Card.Entity.SiteSetting setting = Card.Common.SettingCache.GetSiteSettingByType(Card.CONST.SiteSettingType.BankNo);
                        if (setting != null && !string.IsNullOrEmpty(setting.Value))
                        {
                            this.ltlPaymentDesc.Text = lookUpPayment.TextValue.Replace("{BankNo}", setting.Value.Replace("|", "<br/>"));
                        }
                        else
                        {
                            this.ltlPaymentDesc.Text = lookUpPayment.TextValue;
                        }
                    }
                    else
                    {
                        this.ltlPaymentDesc.Text = lookUpPayment.TextValue;
                    }
                }

                this.txtRemark.Text = order.Remark;
                this.rptList.DataSource = BLL.OrderItemManager.GetItemList(OrderID, this.Passport);
                this.rptList.DataBind();
            }
            else
            {
                Response.Redirect(string.Format("OrderDetail.aspx?oid={0}",this.OrderID));
            }
        }
        #endregion
    }
}
